home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / proc / procMigrate.h < prev    next >
C/C++ Source or Header  |  1990-12-10  |  9KB  |  290 lines

  1. /*
  2.  * procMigrate.h --
  3.  *
  4.  *    Declarations of procedures and constants for process migration. 
  5.  *
  6.  * Copyright 1986, 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  *
  16.  * $ProcMigrate: proto.h,v 1.4 86/03/20 14:00:21 andrew Exp $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _PROCMIGRATE
  20. #define _PROCMIGRATE
  21.  
  22. #ifdef KERNEL
  23. #include <user/proc.h>
  24. #include <procTypes.h>
  25. #include <trace.h>
  26. #include <sys.h>
  27. #include <netTypes.h>
  28. #else
  29. #include <proc.h>
  30. #include <kernel/procTypes.h>
  31. #include <kernel/trace.h>
  32. #include <kernel/sys.h>
  33. #include <kernel/netTypes.h>
  34. #endif
  35.  
  36. /*
  37.  * Flags for the migFlags field in a PCB.
  38.  *     PROC_EVICTING        - [defined in user/proc.h for now]
  39.  *                   Process in the middle of eviction
  40.  *       PROC_WAS_EVICTED    - Process was evicted at some time, so
  41.  *                   the record of the time it used prior
  42.  *                   to eviction is relevant.
  43.  *             
  44.  */
  45. #define PROC_WAS_EVICTED    0x2
  46.  
  47. /*
  48.  * Define a macro to get a valid PCB for a migrated process.  This gets the
  49.  * PCB corresponding to the process ID, and if it is a valid PCB the macro
  50.  * then checks to make sure the process is migrated and from the specified
  51.  * host.
  52.  */
  53.  
  54. #define PROC_GET_MIG_PCB(pid, procPtr, hostID)                 \
  55.     procPtr = Proc_LockPID(pid);                 \
  56.     if (procPtr != (Proc_ControlBlock *) NIL &&         \
  57.             (!(procPtr->genFlags & PROC_FOREIGN) ||     \
  58.             procPtr->peerHostID != remoteHostID)) {        \
  59.         Proc_Unlock(procPtr);                \
  60.          procPtr = (Proc_ControlBlock *) NIL;         \
  61.     }
  62.  
  63. /*
  64.  * Structure to contain information for the arguments to a system call
  65.  * for a migrated process.    The size is the size of the argument passed
  66.  * to or from the other node.  The disposition is SYS_PARAM_IN and/or
  67.  * SYS_PARAM_OUT.
  68.  */
  69.  
  70. typedef struct {
  71.     int size;
  72.     int disposition;
  73. } Proc_ParamInfo;
  74.  
  75. /*
  76.  * Define a simple buffer for passing both buffer size and pointer in
  77.  * a single argument.  (This simplifies the case when the buffer is NIL).
  78.  */
  79.  
  80. typedef struct {
  81.     int size;
  82.     Address ptr;
  83. } Proc_MigBuffer;
  84.  
  85. /* 
  86.  * Generic information sent when migrating a system call back to the
  87.  * home machine.  The processID transferred is the ID of the process
  88.  * on the machine servicing the RPC.
  89.  */
  90.     
  91. typedef struct {
  92.     Proc_PID            processID;
  93.     int                 callNumber;
  94.     Boolean            parseArgs;
  95.     int                numArgs;
  96.     int                replySize;
  97.     Proc_ParamInfo        info[SYS_MAX_ARGS];
  98. } Proc_RemoteCall;
  99.  
  100. /*
  101.  * Declare variables and constants for instrumentation.  First,
  102.  * declare variables for the trace package.  These are followed by
  103.  * structures that are passed into the trace package.  Each trace
  104.  * record contains the process ID of the process being operated upon,
  105.  * whether the operation is done for a process on its home node or a
  106.  * remote one, and either a system call number and ReturnStatus or a
  107.  * migration meta-command such as transferring state.
  108.  */
  109.  
  110. extern Trace_Header proc_TraceHeader;
  111. extern Trace_Header *proc_TraceHdrPtr;
  112. #define PROC_NUM_TRACE_RECS 500
  113.  
  114. /*
  115.  * "Events" for the trace package.
  116.  *
  117.  *    PROC_MIGTRACE_BEGIN_MIG     - starting to transfer a process
  118.  *    PROC_MIGTRACE_END_MIG         - completed transferring a process
  119.  *    PROC_MIGTRACE_COMMAND      - a particular transfer operation
  120.  *    PROC_MIGTRACE_CALL        - a migrated system call
  121.  *    
  122.  */
  123.  
  124. #define PROC_MIGTRACE_BEGIN_MIG     0
  125. #define PROC_MIGTRACE_END_MIG         1
  126. #define PROC_MIGTRACE_COMMAND      2
  127. #define PROC_MIGTRACE_CALL        3
  128. #define PROC_MIGTRACE_MIGTRAP        4
  129.  
  130. typedef struct {
  131.     int callNumber;
  132.     ReturnStatus status;
  133. } Proc_SysCallTrace;
  134.  
  135. typedef struct {
  136.     int type;
  137.     ClientData data;
  138. } Proc_CommandTrace;
  139.  
  140.  
  141. typedef struct {
  142.     Proc_PID processID;
  143.     int flags;
  144.     union {
  145.     Proc_SysCallTrace call;
  146.     Proc_CommandTrace command;
  147.     int filler;
  148.     } info;
  149. } Proc_TraceRecord;
  150.     
  151. /*
  152.  * Flags for Proc_TraceRecords:
  153.  *
  154.  *     PROC_MIGTRACE_START - start of an RPC
  155.  *    PROC_MIGTRACE_HOME  - operation is for a process on its home machine
  156.  *
  157.  * Both of these flags are boolean, so absence of a flag implies its
  158.  * opposite (end of an RPC, or that the operation is for a foreign process).
  159.  */
  160.  
  161. #define PROC_MIGTRACE_START    0x01
  162. #define PROC_MIGTRACE_HOME    0x02
  163.  
  164. /*
  165.  * Define the statistics "version".  This is used to make sure we're
  166.  * gathering consistent sets of statistics.  It's stored in the kernel as
  167.  * a static variable so it can be changed with adb or the debugger if
  168.  * need be.  It's copied into a structure at initialization time.
  169.  */
  170. #ifndef PROC_MIG_STATS_VERSION
  171. #define PROC_MIG_STATS_VERSION 1002
  172. #endif /* PROC_MIG_STATS_VERSION */
  173.  
  174. /*
  175.  * Define a structure to keep track of statistics.
  176.  * Times are kept in terms of hundreds of milliseconds.
  177.  */
  178.  
  179. #define PROC_MIG_TIME_FOR_STATS(time) \
  180.       ((time).seconds * 10 + ((time).microseconds + 50000) / 100000)
  181.  
  182. typedef struct {
  183.     unsigned int    evictions;    /* Number of processes evicted
  184.                             from this host */
  185.     unsigned int    pagesWritten;    /* Number of pages flushed as a
  186.                        result of migration */
  187.     unsigned int    rpcKbytes;     /* Total number of Kbytes sent during
  188.                        migration. */
  189.     unsigned int     timeToMigrate;    /* Cumulative time to export
  190.                        running processes */
  191.     unsigned int     timeToExec;    /* Cumulative time to do remote
  192.                        exec's */
  193.     unsigned int     timeToEvict;    /* Cumulative time to evict
  194.                        processes, individually. */
  195.     unsigned int     totalEvictTime;    /* Cumulative time to evict
  196.                        processes, from start of eviction
  197.                        request to completion of last
  198.                        eviction. */
  199.     unsigned int     totalCPUTime;   /* Cumulative time used by all
  200.                        processes belonging to this host. */
  201.     unsigned int     remoteCPUTime;  /* Cumulative time used by all
  202.                        processes belonging to this host,
  203.                        while executing remotely. */
  204.     unsigned int     evictionCPUTime;/* Cumulative time used by all
  205.                        processes subsequent to first
  206.                        eviction. */
  207. } Proc_MigVarStats;
  208.  
  209. typedef struct {
  210.     unsigned int     statsVersion;   /* Used to distinguish old structures.
  211.                        */
  212.     unsigned int     foreign;     /* Number of foreign processes on
  213.                             this machine */
  214.     unsigned int     remote;        /* Number of processes belonging
  215.                                to this host, running elsewhere */
  216.     unsigned int     exports;    /* Number of times we have exported
  217.                             processes */
  218.     unsigned int     execs;        /* Number of times these were remote
  219.                                execs */
  220.     unsigned int     imports;    /* Number of times we have imported
  221.                                processes */
  222.     unsigned int     errors;        /* Number of times migration has
  223.                        failed */
  224.     unsigned int     returns;    /* Number of times we have had our own
  225.                        process migrate back to us,
  226.                        including evictions */
  227.     unsigned int     evictionsToUs;    /* Number of times we have had our own
  228.                        process evicted. */
  229.     unsigned int     hostCounts[NET_NUM_SPRITE_HOSTS];
  230.                         /* Array of counts of
  231.                        migration to each host */
  232.     unsigned int     migrationsHome; /* Number of times processes migrate
  233.                        home, excluding evictions. */
  234.     unsigned int     evictCalls;     /* Number of times user-level daemon
  235.                        requested evictions. */
  236.     unsigned int     evictsNeeded;     /* Number of times requests resulted
  237.                        in >= 1 evictions. */
  238.     unsigned int     evictionsInProgress;
  239.                         /* Number of processes currently
  240.                        being evicted. */
  241.     unsigned int     processes;    /* Number of exited processes
  242.                        belonging to this host (used
  243.                        for averaging CPU times). */
  244.     Proc_MigVarStats    varStats;     /* Other stats (see above) counted
  245.                        both normally and as
  246.                        sum-of-squares. */
  247.     Proc_MigVarStats    squared;     /* Sum-of-squares. */
  248.                        
  249. } Proc_MigStats;
  250.  
  251.  
  252. /*
  253.  * Macros to manipulate this structure using a monitor.
  254.  */
  255. #define PROC_MIG_INC_STAT(stat) \
  256.     Proc_MigAddToCounter(1, &proc_MigStats.stat, (unsigned int *) NIL)
  257. #define PROC_MIG_DEC_STAT(stat) \
  258.     Proc_MigAddToCounter(-1, &proc_MigStats.stat, (unsigned  int *) NIL)
  259.  
  260.  
  261.  
  262.  
  263. /*
  264.  * Define a structure for passing information via callback for killing
  265.  * a migrated process.  [Not used yet, but potentially.]
  266.  */
  267. typedef struct Proc_DestroyMigProcData {
  268.     Proc_ControlBlock *procPtr;        /* local copy of process to kill */
  269.     ReturnStatus status;        /* status to return when it exits */
  270. } Proc_DestroyMigProcData;
  271.  
  272.  
  273.  
  274. /*
  275.  * External declarations of variables and procedures.
  276.  */
  277. extern int proc_MigDebugLevel;        /* amount of debugging info to print */
  278. extern int proc_MigrationVersion;    /* to distinguish incompatible
  279.                        versions of migration */
  280. extern Boolean proc_DoTrace;        /* controls amount of tracing */
  281. extern Boolean proc_DoCallTrace;    /* ditto */
  282. extern Boolean proc_MigDoStats;        /* ditto */
  283. extern Boolean proc_KillMigratedDebugs;    /* kill foreign processes instead
  284.                        of putting them in the debugger */
  285. extern int proc_AllowMigrationState;    /* how much migration to permit */
  286. extern Proc_MigStats proc_MigStats;    /* migration statistics */
  287.  
  288.  
  289. #endif /* _PROCMIGRATE */
  290.